
import $api from "@/api/index.js"
import $i18n from "@/utils/i18n.js" // 多语言
export default {
	state: {
		accountColumns:[[{
			'label':$i18n.tc('my_wallet.log-screen-all'),
			'action':'all'
		},{
			'label':$i18n.tc('my_wallet.log-screen-income'),
			'action':'income'
		},{
			'label':$i18n.tc('my_wallet.log-screen-payout'),
			'action':'expend'
		}]],
		accountLog:{
			data: [],
			last_page: 1,
			current_page: 1
		}, // 账单记录
		accountParam:{
			page: 1,
			action: 'all',
			type:'money',
			onScreenText:$i18n.tc('my_wallet.log-screen-all'),
		},
		rechargeLog:{
			data: [],
			last_page: 1,
			current_page: 1
		}, // 充值记录
		withTabs:[{
			name: $i18n.tc('withdrawal_log.tabs-1'),
			state : ''
		},{
			name: $i18n.tc('withdrawal_log.tabs-2'),
			state:'1'
		},{
			name: $i18n.tc('withdrawal_log.tabs-3'),
			state:'3'
		},{
			name: $i18n.tc('withdrawal_log.tabs-4'),
			state:'2'
		}],
		withLog:{
			data: [],
			last_page: 1,
			current_page: 1
		},	// 提现记录
		withParam:{
			page: 1,
			state: '',
		},
		integralTabs:[{
			name: $i18n.tc('withdrawal_log.integral-tabs-1'),
		},{
			name: $i18n.tc('withdrawal_log.integral-tabs-2'),
			action:'income'
		},{
			name: $i18n.tc('withdrawal_log.integral-tabs-1'),
			action:'expend'
		}],
		integralLog:{
			data: [],
			last_page: 1,
			current_page: 1
		},	
		integraParam:{
			page: 1,
			action: 'all',
			type:'integral',
		},
	},
	mutations: {
		updateWalletState(state, item) {
			let {
				key,
				val
			} = item
			state[key] = val
		}
		
	},
	actions: {
		async getAccountLog({
			commit,
			state
		}, param){
			let res = await $api.user.getAccountLog(param)
			let oldList = state.accountLog;
			let newList = res.data;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data) // 合并数组
				list = newList;
			}
			commit('updateWalletState', {
				key: 'accountLog',
				val: list
			})
		},
		async getAgentLog({
			commit,
			state
		}, param){
			let res = await $api.user.getAgentLog(param)
			let oldList = state.AgentLog;
			let newList = res.data;
			let list = {}
			 
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data) // 合并数组
				list = newList;
			}
			commit('updateWalletState', {
				key: 'AgentLog',
				val: list
			})
		},
		 
		async getWithLog({
			commit,
			state
		}, param){
			let res = await $api.user.getWithLog(param)
			let oldList = state.withLog;
			let newList = res.data;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data) // 合并数组
				list = newList;
			}
			commit('updateWalletState', {
				key: 'withLog',
				val: list
			})
		},
		async getIntegraLog({
			commit,
			state
		}, param){
			let res = await $api.user.getAccountLog(param)
			// console.log(res)
			let oldList = state.integralLog;
			let newList = res.data;
			let list = {}
			if (param.page == 1) {
				list = newList;
			} else {
				newList.data = oldList.data.concat(newList.data) // 合并数组
				list = newList;
			}
			commit('updateWalletState', {
				key: 'integralLog',
				val: list
			})
		},
	}
}